package com.lk.controller;

import com.lk.config.SystemClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.sql.*;
import java.util.HashMap;
import java.util.Map;


/**
 * TODO:必须加入类功能描述  
 *
 * @author 薄一鸣
 * @date 2024/4/17 14:26
 * @version V1.0
 * @Copyright GUANGHUA-CA
 */
@RestController
public class TestController {

    private final RestTemplate restTemplate;

    @Autowired
    public TestController(RestTemplate restTemplate){
        this.restTemplate = restTemplate;
    }
    public static void main(String[] args) {

        System.setProperty("java.security.krb5.conf", "d:/conf/sichuan/krb5.conf");

        String url = "jdbc:hive2://10.11.130.33:10000/;" +
                "sasl.qop=auth-conf;" +
                "auth=KERBEROS;" +
                "principal=hadoop/bigdata@GHCA.COM;" +
                "user.principal=hadoop/bigdata;" +
                "user.keytab=D:/conf/sichuan/hadoop.keytab;";
        // 加载驱动
        try {
            Class.forName("org.apache.hive.jdbc.HiveDriver");
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
        try (Connection conn = DriverManager.getConnection(url)) {


            try (PreparedStatement ps = conn.prepareStatement("select count(1) from test_ghca"); ResultSet rs = ps.executeQuery()) {
                while (rs.next()) {
                    System.out.println(rs.getString(1));
                }
            }

            System.out.println(" ======================1");

            try (PreparedStatement ps = conn.prepareStatement("update from test_ghca set id = 2 where id = 1"); ) {
                ps.execute();
            }catch (Exception e){
//                e.printStackTrace();
            }


            System.out.println(" ======================2");


            try (PreparedStatement ps = conn.prepareStatement("show tables"); ResultSet rs = ps.executeQuery()) {
                while (rs.next()) {
                    System.out.println(rs.getString(1));
                }
            }

        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }


    @Autowired
    SystemClient systemClient;

    @GetMapping("test1")
    public String test1(){

        return restTemplate.getForObject("http://systemService/test1/" , String.class);
    }
}
